package com.settlement.system.service.impl;

import com.settlement.system.model.entity.OdsOmsShop;
import com.settlement.system.mapper.OdsOmsShopMapper;
import com.settlement.system.service.OdsOmsShopService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.settlement.system.model.query.OdsOmsShopQuery;
import com.settlement.system.model.form.OdsOmsShopForm;
import com.settlement.system.model.vo.OdsOmsShopImportVo;
import org.springframework.beans.BeanUtils;
import org.springframework.util.Assert;
import com.settlement.system.common.util.StringUtils;

/**
 * <p>
 * omss商店 服务实现类
 * </p>
 *
 * @author huangrensen
 * @since 2024-08-06
 */
@Service
public class OdsOmsShopServiceImpl extends ServiceImpl<OdsOmsShopMapper, OdsOmsShop> implements OdsOmsShopService {

    @Override
    public Page<OdsOmsShop> getPage(OdsOmsShopQuery queryParams) {
        // 查询参数
        int pageNum = queryParams.getPageNum();
        int pageSize = queryParams.getPageSize();
        // 查询数据
        Page<OdsOmsShop> page = new Page<>(pageNum, pageSize);
        return this.baseMapper.getPage(page, queryParams);
    }

     @Override
     public boolean saveOdsOmsShop(OdsOmsShopForm odsOmsShopForm) {
         OdsOmsShop odsOmsShop = new OdsOmsShop();
         BeanUtils.copyProperties(odsOmsShopForm, odsOmsShop);
         return this.saveOrUpdate(odsOmsShop);
     }

     @Override
     public OdsOmsShopForm getOdsOmsShopFormData(Long id) {
         OdsOmsShop odsOmsShop = this.getById(id);
         OdsOmsShopForm odsOmsShopForm = new OdsOmsShopForm();
         BeanUtils.copyProperties(odsOmsShop, odsOmsShopForm);
         return odsOmsShopForm;
     }

     @Override
     public boolean deleteOdsOmsShop(String ids) {
        Assert.isTrue(StringUtils.hasText(ids), "删除的数据为空");
        List<Long> idArray = Arrays.stream(ids.split(",")).map(Long::parseLong).collect(Collectors.toList());
        return this.removeByIds(idArray);
     }

    @Override
    public void importData(List<OdsOmsShopImportVo> voList)  {
        List<OdsOmsShop> odsOmsShopList = new ArrayList<>();
        for (OdsOmsShopImportVo importVo : voList) {
            OdsOmsShop odsOmsShop = new OdsOmsShop();
            BeanUtils.copyProperties(importVo, odsOmsShop);
            odsOmsShopList.add(odsOmsShop);
        }
        this.saveOrUpdateBatch(odsOmsShopList);
    }

    @Override
    public List<OdsOmsShopImportVo> findByIds(String idsStr) {
        if (!StringUtils.hasText(idsStr)) {
            return new ArrayList<>();
        }
        List<Long> ids = Arrays.stream(idsStr.split(",")).map(Long::parseLong).collect(Collectors.toList());
        List<OdsOmsShop> odsOmsShopList = this.getBaseMapper().selectBatchIds(ids);
        List<OdsOmsShopImportVo> voList = new ArrayList<>();
        for (OdsOmsShop odsOmsShop : odsOmsShopList) {
            OdsOmsShopImportVo vo = new OdsOmsShopImportVo();
            BeanUtils.copyProperties(odsOmsShop, vo);
            voList.add(vo);
        }
        return voList;
    }
}
